var tree=
{
init: 
    function()
    {
        ff.forElement("IMG", "collapse", function(link)
        {
            console.debug("add collapse "+link);
            ff.event.add(link, "click", tree.onCollapse);
        });
 
        var link=document.getElementById("btnAddYaY");
        var out=document.getElementById("out");
        var toggle=document.getElementById("btnToggle");


        ff.event.add(link,"click", function(ev)
        {
            console.debug("click");
        
            out.appendChild(DIV("Event canceled."));
            
            if (ff.style.hasClass(toggle,"cancel"))
            {
                ff.event.preventDefault(ev);
            }
        }); 

        ff.event.add(toggle ,"click", function(ev)
        {
            ff.dom.clear(this);
            if (ff.style.toggleClass(this, "cancel"))
            {
                this.appendChild(SPAN("Event canceling: on"));
            }
            else
            {
                this.appendChild(SPAN("Event canceling: off"));
            }
            ff.event.preventDefault(ev);
            ff.event.noBubble(ev);
        }); 
    },
onCollapse:
    function(ev)
    {
        console.debug("onCollapse "+ev);
        ff.style.toggleClass(this.parentNode, "collapsed");
        ff.event.preventDefault(ev);
    }
};

console.debug("tree script");
ff.dom.init(window);
ff.event.onload(tree.init);